package 对数器;


import star.插入排序.InsertionSort;

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        System.out.println(compare());
    }

    //随机样本产生器
    private static int[] generateRandomArray(int maxSize,int maxValue){
        int[] arr = new int[(int)((maxSize+1)*Math.random())];
        for (int i = 0; i < arr.length; i++){
            arr[i] = (int) ((maxValue+1)*Math.random()) - (int) (maxValue*Math.random());
        }
        return arr;
    }
    //数组拷贝
    private static int[] copyArray(int[] arr){
        if (arr == null) return null;
        int[] res = new int[arr.length];
        for (int i = 0; i < arr.length; i++) {
            res[i] = arr[i];
        }
        return res;
    }
    //比较
    public static boolean compare(){
        int count = 50000;
        int maxSize = 100;
        int maxValue = 100;
        boolean result = true;
        for (int i = 0; i < count; i++) {
            int[] arr1 = generateRandomArray(maxSize, maxValue);
            int[] arr2 = copyArray(arr1);

            InsertionSort.insertionSort(arr1);
            Arrays.sort(arr2);

            if (!isEqual(arr1,arr2)){
                result = false;
                break;
            }
        }
        return result;
    }
    //判断
    private static boolean isEqual(int[] arr1,int[] arr2){
        if (arr1.length != arr2.length) return false;for (int i = 0; i < arr1.length; i++) {
            if (arr1[i]!=arr2[i]) return false;
        }
        return true;
    }
}
